// $ANTLR 3.2 Sep 23, 2009 12:02:23 D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g 2010-02-06 10:30:50

package ch.kynlang.compiler;
import ch.kynlang.compiler.tree.*;
import ch.kynlang.compiler.symbol.*;
import ch.kynlang.compiler.scope.*;
import ch.kynlang.compiler.type.*;
import java.util.Stack;


import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;import java.util.Stack;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
public class DefineSymbols extends TreeFilter {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "PBODY", "PROPERTY", "WBODY", "WIDGET", "BOOL", "VARACC", "METACC", "ARGLIST", "PACKAGE", "SEMI", "IMPORT", "AS", "IDENTIFIER", "DEF", "EQ", "HASH", "LPAREN", "COMMA", "RPAREN", "COLON", "LBRACE", "RBRACE", "NEW", "DOT", "TRUE", "FALSE", "INTEGER", "FLOAT", "STRINGLITERAL", "CHARACTERLITERAL", "EscapeSequence", "Letter", "JavaIDDigit", "LBRACKET", "RBRACKET", "WS", "COMMENT", "LINE_COMMENT"
    };
    public static final int PACKAGE=12;
    public static final int INTEGER=30;
    public static final int VARACC=9;
    public static final int DEF=17;
    public static final int RBRACE=25;
    public static final int LINE_COMMENT=41;
    public static final int PBODY=4;
    public static final int LBRACE=24;
    public static final int BOOL=8;
    public static final int NEW=26;
    public static final int HASH=19;
    public static final int WIDGET=7;
    public static final int ARGLIST=11;
    public static final int FLOAT=31;
    public static final int EOF=-1;
    public static final int TRUE=28;
    public static final int SEMI=13;
    public static final int LPAREN=20;
    public static final int COLON=23;
    public static final int LBRACKET=37;
    public static final int AS=15;
    public static final int RPAREN=22;
    public static final int IMPORT=14;
    public static final int WS=39;
    public static final int PROPERTY=5;
    public static final int COMMA=21;
    public static final int IDENTIFIER=16;
    public static final int STRINGLITERAL=32;
    public static final int CHARACTERLITERAL=33;
    public static final int WBODY=6;
    public static final int JavaIDDigit=36;
    public static final int EQ=18;
    public static final int RBRACKET=38;
    public static final int DOT=27;
    public static final int COMMENT=40;
    public static final int FALSE=29;
    public static final int EscapeSequence=34;
    public static final int Letter=35;
    public static final int METACC=10;

    // delegates
    // delegators


        public DefineSymbols(TreeNodeStream input) {
            this(input, new RecognizerSharedState());
        }
        public DefineSymbols(TreeNodeStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        

    public String[] getTokenNames() { return DefineSymbols.tokenNames; }
    public String getGrammarFileName() { return "D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g"; }


    // tracks all symbols
    private SymbolTable st = null;

    private IScope currentScope = null;

    private Stack<ContainerSymbol> containers = null;

    public DefineSymbols(TreeNodeStream input, SymbolTable st) {
      this(input);
      this.containers = new Stack<ContainerSymbol>();
      this.st = st;
      this.currentScope = this.st.rootScope;
    }



    // $ANTLR start "topdown"
    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:75:1: topdown : ( packageDef | importDef | varDef | macroDef | widgetDef );
    public final void topdown() throws RecognitionException {
        try {
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:76:3: ( packageDef | importDef | varDef | macroDef | widgetDef )
            int alt1=5;
            switch ( input.LA(1) ) {
            case PACKAGE:
                {
                alt1=1;
                }
                break;
            case IMPORT:
            case AS:
                {
                alt1=2;
                }
                break;
            case DEF:
                {
                alt1=3;
                }
                break;
            case HASH:
                {
                alt1=4;
                }
                break;
            case WIDGET:
                {
                alt1=5;
                }
                break;
            default:
                if (state.backtracking>0) {state.failed=true; return ;}
                NoViableAltException nvae =
                    new NoViableAltException("", 1, 0, input);

                throw nvae;
            }

            switch (alt1) {
                case 1 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:76:5: packageDef
                    {
                    pushFollow(FOLLOW_packageDef_in_topdown76);
                    packageDef();

                    state._fsp--;
                    if (state.failed) return ;

                    }
                    break;
                case 2 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:77:5: importDef
                    {
                    pushFollow(FOLLOW_importDef_in_topdown82);
                    importDef();

                    state._fsp--;
                    if (state.failed) return ;

                    }
                    break;
                case 3 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:78:5: varDef
                    {
                    pushFollow(FOLLOW_varDef_in_topdown88);
                    varDef();

                    state._fsp--;
                    if (state.failed) return ;

                    }
                    break;
                case 4 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:79:5: macroDef
                    {
                    pushFollow(FOLLOW_macroDef_in_topdown94);
                    macroDef();

                    state._fsp--;
                    if (state.failed) return ;

                    }
                    break;
                case 5 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:80:5: widgetDef
                    {
                    pushFollow(FOLLOW_widgetDef_in_topdown100);
                    widgetDef();

                    state._fsp--;
                    if (state.failed) return ;

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "topdown"


    // $ANTLR start "bottomup"
    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:83:1: bottomup : widgetDefExit ;
    public final void bottomup() throws RecognitionException {
        try {
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:84:3: ( widgetDefExit )
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:84:5: widgetDefExit
            {
            pushFollow(FOLLOW_widgetDefExit_in_bottomup115);
            widgetDefExit();

            state._fsp--;
            if (state.failed) return ;

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "bottomup"


    // $ANTLR start "packageDef"
    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:87:1: packageDef : ^( PACKAGE ( IDENTIFIER )+ ) ;
    public final void packageDef() throws RecognitionException {
        KynTree PACKAGE1=null;

        try {
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:88:3: ( ^( PACKAGE ( IDENTIFIER )+ ) )
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:88:5: ^( PACKAGE ( IDENTIFIER )+ )
            {
            PACKAGE1=(KynTree)match(input,PACKAGE,FOLLOW_PACKAGE_in_packageDef131); if (state.failed) return ;

            match(input, Token.DOWN, null); if (state.failed) return ;
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:88:15: ( IDENTIFIER )+
            int cnt2=0;
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==IDENTIFIER) ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:0:0: IDENTIFIER
            	    {
            	    match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_packageDef133); if (state.failed) return ;

            	    }
            	    break;

            	default :
            	    if ( cnt2 >= 1 ) break loop2;
            	    if (state.backtracking>0) {state.failed=true; return ;}
                        EarlyExitException eee =
                            new EarlyExitException(2, input);
                        throw eee;
                }
                cnt2++;
            } while (true);


            match(input, Token.UP, null); if (state.failed) return ;
            if ( state.backtracking==1 ) {

                    PACKAGE1.scope = currentScope;
                    PackageSymbol ps = new PackageSymbol(PACKAGE1);
                    currentScope.define(ps);
                  
            }

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "packageDef"


    // $ANTLR start "importDef"
    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:97:1: importDef : ( ^( AS IDENTIFIER ( IDENTIFIER )+ ) | ^( IMPORT ( IDENTIFIER )+ ) );
    public final void importDef() throws RecognitionException {
        KynTree AS2=null;
        KynTree IMPORT3=null;

        try {
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:98:3: ( ^( AS IDENTIFIER ( IDENTIFIER )+ ) | ^( IMPORT ( IDENTIFIER )+ ) )
            int alt5=2;
            int LA5_0 = input.LA(1);

            if ( (LA5_0==AS) ) {
                alt5=1;
            }
            else if ( (LA5_0==IMPORT) ) {
                alt5=2;
            }
            else {
                if (state.backtracking>0) {state.failed=true; return ;}
                NoViableAltException nvae =
                    new NoViableAltException("", 5, 0, input);

                throw nvae;
            }
            switch (alt5) {
                case 1 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:98:5: ^( AS IDENTIFIER ( IDENTIFIER )+ )
                    {
                    AS2=(KynTree)match(input,AS,FOLLOW_AS_in_importDef159); if (state.failed) return ;

                    match(input, Token.DOWN, null); if (state.failed) return ;
                    match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_importDef161); if (state.failed) return ;
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:98:21: ( IDENTIFIER )+
                    int cnt3=0;
                    loop3:
                    do {
                        int alt3=2;
                        int LA3_0 = input.LA(1);

                        if ( (LA3_0==IDENTIFIER) ) {
                            alt3=1;
                        }


                        switch (alt3) {
                    	case 1 :
                    	    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:0:0: IDENTIFIER
                    	    {
                    	    match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_importDef163); if (state.failed) return ;

                    	    }
                    	    break;

                    	default :
                    	    if ( cnt3 >= 1 ) break loop3;
                    	    if (state.backtracking>0) {state.failed=true; return ;}
                                EarlyExitException eee =
                                    new EarlyExitException(3, input);
                                throw eee;
                        }
                        cnt3++;
                    } while (true);


                    match(input, Token.UP, null); if (state.failed) return ;
                    if ( state.backtracking==1 ) {

                            AS2.scope = currentScope;
                            ImportSymbol is = new ImportSymbol(AS2);
                            boolean success = currentScope.define(is);
                            if(!success) {
                              st.error(new KohYaoNoiError(AS2, "Import alias " + is.name + " already defined"));
                            }
                          
                    }

                    }
                    break;
                case 2 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:107:5: ^( IMPORT ( IDENTIFIER )+ )
                    {
                    IMPORT3=(KynTree)match(input,IMPORT,FOLLOW_IMPORT_in_importDef178); if (state.failed) return ;

                    match(input, Token.DOWN, null); if (state.failed) return ;
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:107:14: ( IDENTIFIER )+
                    int cnt4=0;
                    loop4:
                    do {
                        int alt4=2;
                        int LA4_0 = input.LA(1);

                        if ( (LA4_0==IDENTIFIER) ) {
                            alt4=1;
                        }


                        switch (alt4) {
                    	case 1 :
                    	    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:0:0: IDENTIFIER
                    	    {
                    	    match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_importDef180); if (state.failed) return ;

                    	    }
                    	    break;

                    	default :
                    	    if ( cnt4 >= 1 ) break loop4;
                    	    if (state.backtracking>0) {state.failed=true; return ;}
                                EarlyExitException eee =
                                    new EarlyExitException(4, input);
                                throw eee;
                        }
                        cnt4++;
                    } while (true);


                    match(input, Token.UP, null); if (state.failed) return ;
                    if ( state.backtracking==1 ) {

                            IMPORT3.scope = currentScope;
                            ImportSymbol is = new ImportSymbol(IMPORT3);
                            boolean success = currentScope.define(is);
                            if(!success) {
                              st.error(new KohYaoNoiError(IMPORT3, "Import " + is.name + " already defined"));
                            }
                          
                    }

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "importDef"


    // $ANTLR start "varDef"
    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:118:1: varDef : ^( DEF IDENTIFIER . ) ;
    public final void varDef() throws RecognitionException {
        KynTree DEF4=null;

        try {
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:119:3: ( ^( DEF IDENTIFIER . ) )
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:119:5: ^( DEF IDENTIFIER . )
            {
            DEF4=(KynTree)match(input,DEF,FOLLOW_DEF_in_varDef204); if (state.failed) return ;

            match(input, Token.DOWN, null); if (state.failed) return ;
            match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_varDef206); if (state.failed) return ;
            matchAny(input); if (state.failed) return ;

            match(input, Token.UP, null); if (state.failed) return ;
            if ( state.backtracking==1 ) {

                    DEF4.scope = currentScope;
                    VariableSymbol vs = new VariableSymbol(DEF4);
                    boolean success = currentScope.define(vs);
                    if(!success) {
                      st.error(new KohYaoNoiError(DEF4, "Variable name " + vs.name + " already in use"));
                    }
                  
            }

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "varDef"


    // $ANTLR start "macroDef"
    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:130:1: macroDef : ( ^( HASH IDENTIFIER ^( PBODY ( . )+ ) ) | ^( HASH IDENTIFIER PBODY ) );
    public final void macroDef() throws RecognitionException {
        KynTree HASH5=null;
        KynTree HASH6=null;

        try {
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:131:3: ( ^( HASH IDENTIFIER ^( PBODY ( . )+ ) ) | ^( HASH IDENTIFIER PBODY ) )
            int alt7=2;
            int LA7_0 = input.LA(1);

            if ( (LA7_0==HASH) ) {
                int LA7_1 = input.LA(2);

                if ( (LA7_1==DOWN) ) {
                    int LA7_2 = input.LA(3);

                    if ( (LA7_2==IDENTIFIER) ) {
                        int LA7_3 = input.LA(4);

                        if ( (LA7_3==PBODY) ) {
                            int LA7_4 = input.LA(5);

                            if ( (LA7_4==DOWN) ) {
                                alt7=1;
                            }
                            else if ( (LA7_4==UP) ) {
                                alt7=2;
                            }
                            else {
                                if (state.backtracking>0) {state.failed=true; return ;}
                                NoViableAltException nvae =
                                    new NoViableAltException("", 7, 4, input);

                                throw nvae;
                            }
                        }
                        else {
                            if (state.backtracking>0) {state.failed=true; return ;}
                            NoViableAltException nvae =
                                new NoViableAltException("", 7, 3, input);

                            throw nvae;
                        }
                    }
                    else {
                        if (state.backtracking>0) {state.failed=true; return ;}
                        NoViableAltException nvae =
                            new NoViableAltException("", 7, 2, input);

                        throw nvae;
                    }
                }
                else {
                    if (state.backtracking>0) {state.failed=true; return ;}
                    NoViableAltException nvae =
                        new NoViableAltException("", 7, 1, input);

                    throw nvae;
                }
            }
            else {
                if (state.backtracking>0) {state.failed=true; return ;}
                NoViableAltException nvae =
                    new NoViableAltException("", 7, 0, input);

                throw nvae;
            }
            switch (alt7) {
                case 1 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:131:5: ^( HASH IDENTIFIER ^( PBODY ( . )+ ) )
                    {
                    HASH5=(KynTree)match(input,HASH,FOLLOW_HASH_in_macroDef231); if (state.failed) return ;

                    match(input, Token.DOWN, null); if (state.failed) return ;
                    match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_macroDef233); if (state.failed) return ;
                    match(input,PBODY,FOLLOW_PBODY_in_macroDef236); if (state.failed) return ;

                    match(input, Token.DOWN, null); if (state.failed) return ;
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:131:31: ( . )+
                    int cnt6=0;
                    loop6:
                    do {
                        int alt6=2;
                        int LA6_0 = input.LA(1);

                        if ( ((LA6_0>=PBODY && LA6_0<=LINE_COMMENT)) ) {
                            alt6=1;
                        }


                        switch (alt6) {
                    	case 1 :
                    	    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:0:0: .
                    	    {
                    	    matchAny(input); if (state.failed) return ;

                    	    }
                    	    break;

                    	default :
                    	    if ( cnt6 >= 1 ) break loop6;
                    	    if (state.backtracking>0) {state.failed=true; return ;}
                                EarlyExitException eee =
                                    new EarlyExitException(6, input);
                                throw eee;
                        }
                        cnt6++;
                    } while (true);


                    match(input, Token.UP, null); if (state.failed) return ;

                    match(input, Token.UP, null); if (state.failed) return ;
                    if ( state.backtracking==1 ) {

                            HASH5.scope = currentScope;
                            MacroSymbol ms = new MacroSymbol(HASH5);
                            boolean success = currentScope.define(ms);
                            if(!success) {
                              st.error(new KohYaoNoiError(HASH5, "Macro name " + ms.name + " already in use"));
                            }
                          
                    }

                    }
                    break;
                case 2 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:140:5: ^( HASH IDENTIFIER PBODY )
                    {
                    HASH6=(KynTree)match(input,HASH,FOLLOW_HASH_in_macroDef254); if (state.failed) return ;

                    match(input, Token.DOWN, null); if (state.failed) return ;
                    match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_macroDef256); if (state.failed) return ;
                    match(input,PBODY,FOLLOW_PBODY_in_macroDef258); if (state.failed) return ;

                    match(input, Token.UP, null); if (state.failed) return ;
                    if ( state.backtracking==1 ) {

                            HASH6.scope = currentScope;
                            MacroSymbol ms = new MacroSymbol(HASH6);
                            boolean success = currentScope.define(ms);
                            if(!success) {
                              st.error(new KohYaoNoiError(HASH6, "Macro name " + ms.name + " already in use"));
                            }
                          
                    }

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "macroDef"


    // $ANTLR start "widgetDef"
    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:151:1: widgetDef : ^( WIDGET wtype= IDENTIFIER wname= IDENTIFIER ( PBODY | ^( PBODY ( . )+ ) ) ( WBODY | ^( WBODY ( . )+ ) )? ) ;
    public final void widgetDef() throws RecognitionException {
        KynTree wtype=null;
        KynTree wname=null;
        KynTree WIDGET7=null;

        try {
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:152:3: ( ^( WIDGET wtype= IDENTIFIER wname= IDENTIFIER ( PBODY | ^( PBODY ( . )+ ) ) ( WBODY | ^( WBODY ( . )+ ) )? ) )
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:152:5: ^( WIDGET wtype= IDENTIFIER wname= IDENTIFIER ( PBODY | ^( PBODY ( . )+ ) ) ( WBODY | ^( WBODY ( . )+ ) )? )
            {
            WIDGET7=(KynTree)match(input,WIDGET,FOLLOW_WIDGET_in_widgetDef281); if (state.failed) return ;

            match(input, Token.DOWN, null); if (state.failed) return ;
            wtype=(KynTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_widgetDef285); if (state.failed) return ;
            wname=(KynTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_widgetDef289); if (state.failed) return ;
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:152:49: ( PBODY | ^( PBODY ( . )+ ) )
            int alt9=2;
            int LA9_0 = input.LA(1);

            if ( (LA9_0==PBODY) ) {
                int LA9_1 = input.LA(2);

                if ( (LA9_1==DOWN) ) {
                    alt9=2;
                }
                else if ( (LA9_1==UP||LA9_1==WBODY) ) {
                    alt9=1;
                }
                else {
                    if (state.backtracking>0) {state.failed=true; return ;}
                    NoViableAltException nvae =
                        new NoViableAltException("", 9, 1, input);

                    throw nvae;
                }
            }
            else {
                if (state.backtracking>0) {state.failed=true; return ;}
                NoViableAltException nvae =
                    new NoViableAltException("", 9, 0, input);

                throw nvae;
            }
            switch (alt9) {
                case 1 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:152:50: PBODY
                    {
                    match(input,PBODY,FOLLOW_PBODY_in_widgetDef293); if (state.failed) return ;

                    }
                    break;
                case 2 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:152:56: ^( PBODY ( . )+ )
                    {
                    match(input,PBODY,FOLLOW_PBODY_in_widgetDef296); if (state.failed) return ;

                    match(input, Token.DOWN, null); if (state.failed) return ;
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:152:64: ( . )+
                    int cnt8=0;
                    loop8:
                    do {
                        int alt8=2;
                        int LA8_0 = input.LA(1);

                        if ( ((LA8_0>=PBODY && LA8_0<=LINE_COMMENT)) ) {
                            alt8=1;
                        }


                        switch (alt8) {
                    	case 1 :
                    	    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:0:0: .
                    	    {
                    	    matchAny(input); if (state.failed) return ;

                    	    }
                    	    break;

                    	default :
                    	    if ( cnt8 >= 1 ) break loop8;
                    	    if (state.backtracking>0) {state.failed=true; return ;}
                                EarlyExitException eee =
                                    new EarlyExitException(8, input);
                                throw eee;
                        }
                        cnt8++;
                    } while (true);


                    match(input, Token.UP, null); if (state.failed) return ;

                    }
                    break;

            }

            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:152:69: ( WBODY | ^( WBODY ( . )+ ) )?
            int alt11=3;
            int LA11_0 = input.LA(1);

            if ( (LA11_0==WBODY) ) {
                int LA11_1 = input.LA(2);

                if ( (LA11_1==DOWN) ) {
                    alt11=2;
                }
                else if ( (LA11_1==UP) ) {
                    alt11=1;
                }
            }
            switch (alt11) {
                case 1 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:152:70: WBODY
                    {
                    match(input,WBODY,FOLLOW_WBODY_in_widgetDef304); if (state.failed) return ;

                    }
                    break;
                case 2 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:152:76: ^( WBODY ( . )+ )
                    {
                    match(input,WBODY,FOLLOW_WBODY_in_widgetDef307); if (state.failed) return ;

                    match(input, Token.DOWN, null); if (state.failed) return ;
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:152:84: ( . )+
                    int cnt10=0;
                    loop10:
                    do {
                        int alt10=2;
                        int LA10_0 = input.LA(1);

                        if ( ((LA10_0>=PBODY && LA10_0<=LINE_COMMENT)) ) {
                            alt10=1;
                        }


                        switch (alt10) {
                    	case 1 :
                    	    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:0:0: .
                    	    {
                    	    matchAny(input); if (state.failed) return ;

                    	    }
                    	    break;

                    	default :
                    	    if ( cnt10 >= 1 ) break loop10;
                    	    if (state.backtracking>0) {state.failed=true; return ;}
                                EarlyExitException eee =
                                    new EarlyExitException(10, input);
                                throw eee;
                        }
                        cnt10++;
                    } while (true);


                    match(input, Token.UP, null); if (state.failed) return ;

                    }
                    break;

            }


            match(input, Token.UP, null); if (state.failed) return ;
            if ( state.backtracking==1 ) {

                  // push container widgets on a stack
                  WIDGET7.scope = currentScope;
                  ComponentSymbol c = ComponentSymbolFactory.createComponent(WIDGET7);
                  
                  if(c != null) {
                    boolean success = currentScope.define(c);
                    if(success) {
                      if(c instanceof ContainerSymbol && containers.size() == 0) {
                        // root container
                        // check if it can be root
                        ContainerSymbol cs = (ContainerSymbol) c;
                        if(cs.canBeRoot) {
              	         containers.push(cs);
              	        } else {
              	         st.error(new KohYaoNoiError(WIDGET7, "Widget " + c.name + " is not a valid root container"));
              	        }
              	      } else if(c instanceof UIComponent && containers.size() == 0) {
              	       // we have no container for this UIComponent!
              	       st.error(new KohYaoNoiError(WIDGET7, "Widget " + c.name + " must be inside a container"));
              	      } else if(containers.size() > 0) {
              	       // there is at least 1 container on the stack
              	       c.parentComponent = containers.peek();
              	       // check if it's a container
              	       if(c instanceof ContainerSymbol) {
              	         containers.push((ContainerSymbol) c);
              	       }
              	      }
              	      
                    } else {
                      st.error(new KohYaoNoiError(WIDGET7, "Widget name " + c.name + " already in use"));
                    }
                  } else {
                    // error!! 
                    st.error(new KohYaoNoiError(WIDGET7, WIDGET7.getChild(0).getText() + " is not a widget")); 
                  }
                
            }

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "widgetDef"


    // $ANTLR start "widgetDefExit"
    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:192:1: widgetDefExit : ^( WIDGET wtype= IDENTIFIER wname= IDENTIFIER ( PBODY | ^( PBODY ( . )+ ) ) ( WBODY | ^( WBODY ( . )+ ) )? ) ;
    public final void widgetDefExit() throws RecognitionException {
        KynTree wtype=null;
        KynTree wname=null;

        try {
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:193:3: ( ^( WIDGET wtype= IDENTIFIER wname= IDENTIFIER ( PBODY | ^( PBODY ( . )+ ) ) ( WBODY | ^( WBODY ( . )+ ) )? ) )
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:193:5: ^( WIDGET wtype= IDENTIFIER wname= IDENTIFIER ( PBODY | ^( PBODY ( . )+ ) ) ( WBODY | ^( WBODY ( . )+ ) )? )
            {
            match(input,WIDGET,FOLLOW_WIDGET_in_widgetDefExit334); if (state.failed) return ;

            match(input, Token.DOWN, null); if (state.failed) return ;
            wtype=(KynTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_widgetDefExit338); if (state.failed) return ;
            wname=(KynTree)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_widgetDefExit342); if (state.failed) return ;
            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:193:49: ( PBODY | ^( PBODY ( . )+ ) )
            int alt13=2;
            int LA13_0 = input.LA(1);

            if ( (LA13_0==PBODY) ) {
                int LA13_1 = input.LA(2);

                if ( (LA13_1==DOWN) ) {
                    alt13=2;
                }
                else if ( (LA13_1==UP||LA13_1==WBODY) ) {
                    alt13=1;
                }
                else {
                    if (state.backtracking>0) {state.failed=true; return ;}
                    NoViableAltException nvae =
                        new NoViableAltException("", 13, 1, input);

                    throw nvae;
                }
            }
            else {
                if (state.backtracking>0) {state.failed=true; return ;}
                NoViableAltException nvae =
                    new NoViableAltException("", 13, 0, input);

                throw nvae;
            }
            switch (alt13) {
                case 1 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:193:50: PBODY
                    {
                    match(input,PBODY,FOLLOW_PBODY_in_widgetDefExit346); if (state.failed) return ;

                    }
                    break;
                case 2 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:193:56: ^( PBODY ( . )+ )
                    {
                    match(input,PBODY,FOLLOW_PBODY_in_widgetDefExit349); if (state.failed) return ;

                    match(input, Token.DOWN, null); if (state.failed) return ;
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:193:64: ( . )+
                    int cnt12=0;
                    loop12:
                    do {
                        int alt12=2;
                        int LA12_0 = input.LA(1);

                        if ( ((LA12_0>=PBODY && LA12_0<=LINE_COMMENT)) ) {
                            alt12=1;
                        }


                        switch (alt12) {
                    	case 1 :
                    	    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:0:0: .
                    	    {
                    	    matchAny(input); if (state.failed) return ;

                    	    }
                    	    break;

                    	default :
                    	    if ( cnt12 >= 1 ) break loop12;
                    	    if (state.backtracking>0) {state.failed=true; return ;}
                                EarlyExitException eee =
                                    new EarlyExitException(12, input);
                                throw eee;
                        }
                        cnt12++;
                    } while (true);


                    match(input, Token.UP, null); if (state.failed) return ;

                    }
                    break;

            }

            // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:193:69: ( WBODY | ^( WBODY ( . )+ ) )?
            int alt15=3;
            int LA15_0 = input.LA(1);

            if ( (LA15_0==WBODY) ) {
                int LA15_1 = input.LA(2);

                if ( (LA15_1==DOWN) ) {
                    alt15=2;
                }
                else if ( (LA15_1==UP) ) {
                    alt15=1;
                }
            }
            switch (alt15) {
                case 1 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:193:70: WBODY
                    {
                    match(input,WBODY,FOLLOW_WBODY_in_widgetDefExit357); if (state.failed) return ;

                    }
                    break;
                case 2 :
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:193:76: ^( WBODY ( . )+ )
                    {
                    match(input,WBODY,FOLLOW_WBODY_in_widgetDefExit360); if (state.failed) return ;

                    match(input, Token.DOWN, null); if (state.failed) return ;
                    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:193:84: ( . )+
                    int cnt14=0;
                    loop14:
                    do {
                        int alt14=2;
                        int LA14_0 = input.LA(1);

                        if ( ((LA14_0>=PBODY && LA14_0<=LINE_COMMENT)) ) {
                            alt14=1;
                        }


                        switch (alt14) {
                    	case 1 :
                    	    // D:\\My Dropbox\\development\\eclipse\\KohYaoNoi\\src\\ch\\kynlang\\compiler\\DefineSymbols.g:0:0: .
                    	    {
                    	    matchAny(input); if (state.failed) return ;

                    	    }
                    	    break;

                    	default :
                    	    if ( cnt14 >= 1 ) break loop14;
                    	    if (state.backtracking>0) {state.failed=true; return ;}
                                EarlyExitException eee =
                                    new EarlyExitException(14, input);
                                throw eee;
                        }
                        cnt14++;
                    } while (true);


                    match(input, Token.UP, null); if (state.failed) return ;

                    }
                    break;

            }


            match(input, Token.UP, null); if (state.failed) return ;
            if ( state.backtracking==1 ) {

                  // pop container widgets from stack
                  for(String type : ComponentSymbolFactory.CONTAINERS) {
                    if(wtype.getText().equals(type) && containers.size() > 0) {
                      containers.pop();
                      break;
                    }
                  }
                
            }

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "widgetDefExit"

    // Delegated rules


 

    public static final BitSet FOLLOW_packageDef_in_topdown76 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_importDef_in_topdown82 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_varDef_in_topdown88 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_macroDef_in_topdown94 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_widgetDef_in_topdown100 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_widgetDefExit_in_bottomup115 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_PACKAGE_in_packageDef131 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_IDENTIFIER_in_packageDef133 = new BitSet(new long[]{0x0000000000010008L});
    public static final BitSet FOLLOW_AS_in_importDef159 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_IDENTIFIER_in_importDef161 = new BitSet(new long[]{0x0000000000010000L});
    public static final BitSet FOLLOW_IDENTIFIER_in_importDef163 = new BitSet(new long[]{0x0000000000010008L});
    public static final BitSet FOLLOW_IMPORT_in_importDef178 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_IDENTIFIER_in_importDef180 = new BitSet(new long[]{0x0000000000010008L});
    public static final BitSet FOLLOW_DEF_in_varDef204 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_IDENTIFIER_in_varDef206 = new BitSet(new long[]{0x000003FFFFFFFFF0L});
    public static final BitSet FOLLOW_HASH_in_macroDef231 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_IDENTIFIER_in_macroDef233 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_PBODY_in_macroDef236 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_HASH_in_macroDef254 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_IDENTIFIER_in_macroDef256 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_PBODY_in_macroDef258 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_WIDGET_in_widgetDef281 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_IDENTIFIER_in_widgetDef285 = new BitSet(new long[]{0x0000000000010000L});
    public static final BitSet FOLLOW_IDENTIFIER_in_widgetDef289 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_PBODY_in_widgetDef293 = new BitSet(new long[]{0x0000000000000048L});
    public static final BitSet FOLLOW_PBODY_in_widgetDef296 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_WBODY_in_widgetDef304 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_WBODY_in_widgetDef307 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_WIDGET_in_widgetDefExit334 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_IDENTIFIER_in_widgetDefExit338 = new BitSet(new long[]{0x0000000000010000L});
    public static final BitSet FOLLOW_IDENTIFIER_in_widgetDefExit342 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_PBODY_in_widgetDefExit346 = new BitSet(new long[]{0x0000000000000048L});
    public static final BitSet FOLLOW_PBODY_in_widgetDefExit349 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_WBODY_in_widgetDefExit357 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_WBODY_in_widgetDefExit360 = new BitSet(new long[]{0x0000000000000004L});

}